﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Utility;
using Data;

namespace Website.UC
{
    public partial class UC_Admin : System.Web.UI.UserControl
    {
        Tbl_AdminBus adminBus = new Tbl_AdminBus();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadData();
            }
        }
        private void loadData()
        {
            GridView1.DataSource = adminBus.getListAdmin();
            GridView1.DataBind();
        }
        private void clear()
        {
            lblId.Text = "";
            txtUsername.Text = "";
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            clear();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text.Length == 0)
            {
                WebHelper.ShowMessage("Username not null", Page);
            }
            else
            {
                tbl_admin ta = new tbl_admin();
                ta.username= txtUsername.Text;

                if (lblId.Text.Length == 0)
                {
                    adminBus.insertAdmin(ta);
                }
                else
                {
                    ta.admin_id = Int32.Parse(lblId.Text);
                    adminBus.updateAdmin(ta);
                }
                clear();
                loadData();
            }
        }

        
    }
}